package Thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 邓大帅
 * Date: 2024-01-24
 * Time: 20:17
 */
//wait和notify是Object方法，所以只要是个类对象(不是基本数据类型)，都可以使用这两个方法
public class ThreadDemo7 {
    public static void main(String[] args) throws InterruptedException {
        Object object = new Object();
        Thread thread = new Thread(() -> {
            synchronized (object) {
                System.out.println("wait 开始");
                try {
                    object.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("wait 结束");
            }
        });
        thread.start();
        Thread.sleep(1000);
        Thread thread1 = new Thread(() -> {
             synchronized (object) {
                 System.out.println("notify 开始");
                 object.notify();
                 System.out.println("notify 结束");
             }
        });
        thread1.start();
    }
}
